package com.urfresh.sp.flume.avro;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Destination;
import java.util.Map;

/**
 * Created by urfresh.mark on 2016/7/5.
 */
@Component
public class Client {

	@Autowired
	MyRpcClientFacade client;

	@Autowired
	JmsTemplate jmsTemplate;

	/**
	 * 发送到flume中
	 * @param value 需要发送的数据
	 * @param topic 队列名
	 */
	public void sendToFlume(String value, String topic) {
		if (null == value || value.isEmpty())
			return;
		sendToQueue(topic, value);
		client.sendBatchDataToFlume(value, topic);
	}

	/**
	 * 发送到flume中
	 * @param value 需要发送的数据
	 * @param topic 队列名
	 */
	public void sendToFlume(String value, String topic, Map<String, String> attachData) {
		if (null == value || value.isEmpty())
			return;
		sendToQueue(topic, value);
		client.sendBatchDataToFlume(value, topic, attachData);
	}

	Destination destination = new ActiveMQQueue("traffic_bind_user");

	private void sendToQueue(String topic, String value){
		if(topic.equals("urfresh.track.app.data")){
			jmsTemplate.convertAndSend(destination, value);
		}
	}

}
